{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 4, 6]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nums = [8,2,3,4,5,6]\n",
    "nums[1::2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = {1,2,3,4,5,6}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1000000000"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inf = int(1e9)\n",
    "inf"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 树"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Definition for a binary tree node.\n",
    "class TreeNode(object):\n",
    "    def __init__(self, x):\n",
    "        self.val = x\n",
    "        self.left = None\n",
    "        self.right = None\n",
    "\n",
    "class Solution(object):\n",
    "    def isSubtree(self, s, t):\n",
    "        \"\"\"\n",
    "        :type s: TreeNode\n",
    "        :type t: TreeNode\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        if not s and not t:\n",
    "            return True\n",
    "        if not s or not t:\n",
    "            return False\n",
    "        return self.isSameTree(s, t) or self.isSubtree(s.left, t) or self.isSubtree(s.right, t)\n",
    "        \n",
    "    def isSameTree(self, s, t):\n",
    "        if not s and not t:\n",
    "            return True\n",
    "        if not s or not t:\n",
    "            return False\n",
    "        return s.val == t.val and self.isSameTree(s.left, t.left) and self.isSameTree(s.right, t.right)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = TreeNode(1)\n",
    "s.left,s.right = 2 , 3\n",
    "t = TreeNode(3)\n",
    "t.left,t.right = 4,5\n",
    "q = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### input"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "输入a,b空格隔开: 1 2\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('1', '2')"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# a,b =input('输入a,b空格隔开:').split()\n",
    "# a,b\n",
    "#此时a,b为str型\n",
    "a,b =map(int,input('输入a,b空格隔开:').split())\n",
    "#此时a,b为int型\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 123\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 2 3\n"
     ]
    }
   ],
   "source": [
    "n, m, c = input()\n",
    "print(n, m,c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "a = 1\n",
    "b = 2\n",
    "print(isinstance(a,int))\n",
    "print(math.ceil(1) == a)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello%20word\n"
     ]
    }
   ],
   "source": [
    "s = 'hello word'\n",
    "print(s.replace(' ','%20'))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 1  3\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('1', '3')"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a,b = input().split()\n",
    "a,b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 12 4\n"
     ]
    }
   ],
   "source": [
    "N, L = map(int, input().split())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "16"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "N+L"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3, 4, 5, 6, 8]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nums = sorted(nums)\n",
    "nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "if nums[0] == 2 : print('1')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### lambda函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 9, 24, 12, 27]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "foo = [2, 18, 9, 22, 17, 24, 8, 12, 27]\n",
    "\n",
    "list((filter(lambda x: x % 3 == 0,foo)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[4, 36, 18, 44, 34, 48, 16, 24, 54]"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(map(lambda x, y: x + y, foo,foo))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 36, 49, 64, 81]"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(map(lambda x: x * x, [1, 2, 3, 4, 5, 6, 7, 8, 9]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "** filter函数。此时lambda函数用于指定过滤列表元素的条件。例如filter(lambda x: x % 3 == 0, [1, 2, 3])指定将列表[1,2,3]中能够被3整除的元素过滤出来，其结果是[3]。\n",
    "\n",
    "sorted函数。此时lambda函数用于指定对列表中所有元素进行排序的准则。例如sorted([1, 2, 3, 4, 5, 6, 7, 8, 9], key=lambda x: abs(5-x))将列表[1, 2, 3, 4, 5, 6, 7, 8, 9]按照元素与5距离从小到大进行排序，其结果是[5, 4, 6, 3, 7, 2, 8, 1, 9]。\n",
    "\n",
    "map函数。此时lambda函数用于指定对列表中每一个元素的共同操作。例如map(lambda x: x+1, [1, 2,3])将列表[1, 2, 3]中的元素分别加1，其结果[2, 3, 4]。\n",
    "\n",
    "reduce函数。此时lambda函数用于指定列表中两两相邻元素的结合条件。例如reduce(lambda a, b: '{}, {}'.format(a, b), [1, 2, 3, 4, 5, 6, 7, 8, 9])将列表 [1, 2, 3, 4, 5, 6, 7, 8, 9]中的元素从左往右两两以逗号分隔的字符的形式依次结合起来，其结果是'1, 2, 3, 4, 5, 6, 7, 8, 9'。\n",
    "————————————————\n",
    "\n",
    "原文链接：https://blog.csdn.net/zjuxsl/article/details/79437563 **"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### reversed()反向迭代器这个函数的复杂度低于[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'6 5 4 3 2 8'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nums = ['8','2','3','4','5','6']\n",
    "' '.join(reversed(nums))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['6', '5', '4', '3', '2', '8']"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nums.reverse()\n",
    "nums"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### split和strip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['sky', 'is', 'blue', 'the']"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = '  the    blue    is sky   '\n",
    "s.split()[::-1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[8, 2, 3, 4, 5, 6, [1, 2, 3], [1, 2, 3]]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "i,j = 1,3\n",
    "lst = list(range(1,j+1))\n",
    "nums.append(lst)\n",
    "nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "not 4%2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{2, 3, 4, 5, 6, 8}\n"
     ]
    }
   ],
   "source": [
    "set1 = set(nums)\n",
    "print(set1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{0: 8, 1: 2, 2: 3, 3: 4, 4: 5}\n"
     ]
    }
   ],
   "source": [
    "dict = {}\n",
    "for index,num in enumerate(nums):\n",
    "    if 10 - num not in dict:\n",
    "        dict[index] = num\n",
    "    else:\n",
    "        print(dict)\n",
    "        break\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### [::-1]及奇数偶数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 4, 6]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# [start : end: step]，表示从start以step为步长直到end，但不包括end，start默认值为0，end默认值为到结束，step默认为1\n",
    "nums = [1,2,3,4,5,6,7]\n",
    "nums[1::2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 3, 4]\n"
     ]
    }
   ],
   "source": [
    "nums.sort()\n",
    "print(nums[:3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 3, 5]\n",
      "[2, 4, 6]\n",
      "[1, 3, 5, 2, 4, 6]\n"
     ]
    }
   ],
   "source": [
    "odd = nums[::2]\n",
    "print(odd)\n",
    "even = nums[1::2]\n",
    "print(even)\n",
    "odd.extend(even)\n",
    "print(odd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst = [1,1,3,4,5]\n",
    "lst.count(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "a = [1,2,3,1,1,1,1,4,2]\n",
    "a.sort()\n",
    "print(a[len(a)//2+1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = dict()\n",
    "d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "min(list_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid token (<ipython-input-29-3198dd0ebe6e>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-29-3198dd0ebe6e>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    a = 00011111\u001b[0m\n\u001b[1;37m               ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid token\n"
     ]
    }
   ],
   "source": [
    "a = 00011111\n",
    "s = '00012345'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1111\n"
     ]
    }
   ],
   "source": [
    "if '5' in s:\n",
    "    print(1111)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "4\n",
      "4\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "k = 0\n",
    "for i in '123444':\n",
    "    if i == '4':\n",
    "        k += 1\n",
    "        print(i)\n",
    "print(k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11101000\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "n = 11101000\n",
    "l = str(n)\n",
    "print(l)\n",
    "k = 0\n",
    "for i in l:\n",
    "    if i == '1':\n",
    "        k += 1\n",
    "        print(i)\n",
    "print(k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "def hammingWeight(n: int) -> int:\n",
    "    l = str(n)\n",
    "    k = 0\n",
    "    for i in l:\n",
    "        if i == '1':\n",
    "            k = k +1\n",
    "            print(i)\n",
    "            continue\n",
    "    return int(k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid token (<ipython-input-25-88a8fb81e652>, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-25-88a8fb81e652>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    hammingWeight(0001231141)\u001b[0m\n\u001b[1;37m                           ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid token\n"
     ]
    }
   ],
   "source": [
    "hammingWeight(0001231141)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 12345\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'0b11000000111001'"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bin(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 1\n",
    "a << 3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n"
     ]
    }
   ],
   "source": [
    "maxnum = '1'\n",
    "for i in range(2):\n",
    "    maxnum = maxnum + '0'\n",
    "print(type(maxnum))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "f0 = 1\n",
    "f1 = 1\n",
    "f2 = 1\n",
    "n = 3\n",
    "for i in range(1,n):\n",
    "    f2 = f1 + f0\n",
    "    f0 = f1\n",
    "    f1 = f2\n",
    "print(f2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "\n"
     ]
    }
   ],
   "source": [
    "for i in range(2,3):\n",
    "    print('1\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "IndentationError: unindent does not match any outer indentation level\n",
    "                      ^\n",
    "    while head != None:\n",
    "Line 10  (Solution.py)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 1\n",
    "b = 2\n",
    "c = 3\n",
    "a,b,c = c,a,b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3 1 2\n"
     ]
    }
   ],
   "source": [
    "print(a,b,c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "AttributeError: 'NoneType' object has no attribute 'next'\n",
    "    head,pre,head.next=head.next,head,pre\n",
    "Line 13 in reverseList (Solution.py)\n",
    "    ret = Solution().reverseList(param_1)\n",
    "Line 54 in _driver (Solution.py)\n",
    "    _driver()\n",
    "Line 67 in <module> (Solution.py)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Definition for singly-linked list.\n",
    "class ListNode:\n",
    "    def __init__(self, x):\n",
    "        self.val = x\n",
    "        self.next = None\n",
    "\n",
    "class Solution:\n",
    "    def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:\n",
    "        head = ListNode()\n",
    "        cur = head\n",
    "\n",
    "        while l1 and l2:\n",
    "            if l1.val > l2.val:\n",
    "                cur.next = l2\n",
    "                # cur.next,l2 = l2,l2.next\n",
    "                cur = cur.next\n",
    "                l2 = l2.next\n",
    "            elif l1.val < l2.val:\n",
    "                cur.next = l1\n",
    "                cur = cur.next\n",
    "                l1 = l1.next\n",
    "            else:\n",
    "                cur.next = l1\n",
    "                cur = cur.next\n",
    "                cur.next = l2\n",
    "                cur = cur.next\n",
    "                l1 = l1.next\n",
    "                l2 = l2.next\n",
    "        if l1 == None:\n",
    "            cur.next = l2\n",
    "        if l2 == None:\n",
    "            cur.next = l1\n",
    "        \n",
    "        return head.next"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Definition for singly-linked list.\n",
    "# class ListNode:\n",
    "#     def __init__(self, x):\n",
    "#         self.val = x\n",
    "#         self.next = None\n",
    "\n",
    "class Solution:\n",
    "    def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:\n",
    "        cur = dum = ListNode(0)\n",
    "        while l1 and l2:\n",
    "            if l1.val < l2.val:\n",
    "                # cur.next, l1 = l1, l1.next\n",
    "                cur.next = l1\n",
    "                l1 = l1.next\n",
    "                cur = cur.next\n",
    "            elif l1.val > l2.val:\n",
    "                # cur.next, l2 = l2, l2.next\n",
    "                cur.next = l2\n",
    "                l2 = l2.next\n",
    "                cur = cur.next\n",
    "            elif l1.val == l2.val:\n",
    "                cur.next = l1\n",
    "                cur = cur.next\n",
    "                cur.next = l2\n",
    "                cur = cur.next\n",
    "                l1 = l1.next\n",
    "                l2 = l2.next\n",
    "                \n",
    "            # cur = cur.next\n",
    "        # cur.next = l1 if l1 else l2\n",
    "        if l1 == None:\n",
    "            cur.next = l2\n",
    "        if l2 == None:\n",
    "            cur.next = l1\n",
    "        return dum.next"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "t\n"
     ]
    }
   ],
   "source": [
    "s = '12345j'\n",
    "if '1' in s:\n",
    "    print('t')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "dict = {'1':4,'2':5,'3':6}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in dict:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a 2\n",
      "b 4\n",
      "c 5\n",
      "a 2\n",
      "b 4\n",
      "c 5\n"
     ]
    }
   ],
   "source": [
    "#orderedDict\n",
    "from collections import OrderedDict\n",
    "original_dict = {'a': 2, 'b': 4, 'c': 5}\n",
    "for key, value in original_dict.items():\n",
    "    print (key, value)\n",
    "\n",
    "ordered_dict = OrderedDict([('a', 2), ('b', 4), ('c', 5)])\n",
    "for key, value in ordered_dict.items():\n",
    "    print (key, value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
